package com.lj.back.manage.scaffold.common.security;

import com.lj.back.manage.scaffold.common.util.CommonUtil;
import org.apache.commons.lang3.ArrayUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.util.Arrays;

/**
 * XSS过滤器
 * @author lv
 * @version 1.0.0
 */
public class GlobalSecurityHttpServletRequestWrapper extends HttpServletRequestWrapper{

    public GlobalSecurityHttpServletRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String getQueryString() {
        return CommonUtil.inputFilter(super.getQueryString());
    }

    @Override
    public String getParameter(String name) {
        return CommonUtil.inputFilter(super.getParameter(name));
    }

    @Override
    public String[] getParameterValues(String name) {
        String[] values = super.getParameterValues(name);
        if (ArrayUtils.isEmpty(values)) {
            return values;
        }
        return Arrays.stream(values).map(CommonUtil::inputFilter).toArray(String[]::new);
    }
}
